{{ template "layout/adminheader" .}}
<main id="body">
    <div class="container">


        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        <form action="" method="post" id="form">
                            <h4 class="card-title">使用模板【{{.tag.Name}}】 - 添加标签</h4>
                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label">所属分类：</label>
                                <div class="col-sm-10">
                                    <select name="cate_id" class="custom-select" id="lang">
                                        {{$cateid := .tag.TagCateID}}
                                        {{range .cate}}
                                            <option value="{{.ID}}" {{if eq $cateid .ID}} selected {{end}}>{{.Name}}</option>
                                        {{end}}
                                    </select>
                                </div>
                            </div>

                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label">TAG名：</label>
                                <div class="col-sm-10">
                                    <input type="text" name="name" id="name" placeholder="" value="{{.tag.Name}}" class="form-control">						</div>
                            </div>

                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label">描述：</label>
                                <div class="col-sm-10">
                                    <textarea name="comment" id="comment" class="form-control" style="width: 100%; height: 100px; ">{{.tag.Comment}}</textarea>
                                </div>
                            </div>

                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label">TAG排序：</label>
                                <div class="col-sm-10">
                                    <input type="text" name="rank" id="rank" placeholder="" value="{{.tag.Rank}}" class="form-control">
                                </div>
                            </div>


                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label">启用：</label>
                                <div class="col-sm-10">
                                    {{if .tag.Enable }}
                                        <label class="custom-input custom-radio"><input type="radio" name="enable" value="1"  checked="checked"> 是</label> &nbsp;
                                        <label class="custom-input custom-radio"><input type="radio" name="enable" value="0"> 否</label> &nbsp;
                                    {{else}}
                                        <label class="custom-input custom-radio"><input type="radio" name="enable" value="1"> 是</label> &nbsp;
                                        <label class="custom-input custom-radio"><input type="radio" name="enable" value="0"   checked="checked"> 否</label> &nbsp;
                                    {{end}}
                                </div>
                            </div>

                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label">默认值：</label>
                                <div class="col-sm-10">
                                    <label class="custom-input custom-radio"><input type="radio" name="isdefault" value="1"> 是</label> &nbsp;
                                    <label class="custom-input custom-radio"><input type="radio" name="isdefault" value="0"   checked="checked"> 否</label> &nbsp;
                                </div>
                            </div>


                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label">主题颜色：</label>
                                <div class="col-sm-10">
                                    <select class="custom-select custom-select-md" name="style" data-selected="{{.tag.Style}}">
                                        <option value="secondary" {{if eq .tag.Style "secondary"}} selected {{end}}>灰色</option>
                                        <option value="primary" {{if eq .tag.Style "primary"}} selected {{end}}>蓝色</option>
                                        <option value="danger" {{if eq .tag.Style "danger"}} selected {{end}}>红色</option>
                                        <option value="warning" {{if eq .tag.Style "warning"}} selected {{end}}>橙色</option>
                                        <option value="success" {{if eq .tag.Style "success"}} selected {{end}}>绿色</option>
                                        <option value="info" {{if eq .tag.Style "info"}} selected {{end}}>天蓝</option>
                                        <option value="dark" {{if eq .tag.Style "dark"}} selected {{end}}>黑色</option>
                                        <option value="light" {{if eq .tag.Style "light"}} selected {{end}}>亮色</option>
                                        <option value="white" {{if eq .tag.Style "white"}} selected {{end}}>白色</option>
                                    </select>
                                </div>
                            </div>



                            <div class="form-group row">
                                <label for="inputPassword3" class="col-sm-2 form-control-label"></label>
                                <div class="col-sm-10">
                                    <button type="button" class="btn btn-primary btn-block" id="submit" data-loading-text="正在提交...">确定</button>
                                    <button type="button" class="btn btn-secondary btn-block mt-3" onclick="javascript:history.back();">返回</button>
                                </div>
                            </div>
                        </form>
                        <p class="small text-grey">注：请谨慎编辑版块，一旦确定后不要轻易变动，否则可能会导致数据关联错误，一般在正式运营时就不要再变动。</p>
                    </div>
                </div>
            </div>
        </div>


    </div>
</main>

<script>
    var jform = $("#form");
    var jsubmit = $("#submit");

    jsubmit.on('click', function () {
        var postdata = jform.serializeObject();
        $.ajax({
            url: "/api/v1/tag?token=" + admintoken,
            data: postdata,
            type: "POST",

            success: function(res) {
                //成功
                console.log(res)
                if (res.code == 200) {
                    $.alert("添加成功")
                    setTimeout(function(){
                        location.href="/admin/tag/list.html?token=" + admintoken
                    }, 2000)
                }
            },
            error: function() {
                //失败
            }
        })
    });
</script>
{{ template "layout/adminfooter" .}}